package com.dao.impl;

import com.dao.BgUserDao;
import com.entity.BgUser;
import com.entity.User;
import com.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.SQLException;

public class BgUserDaoImpl implements BgUserDao {
    private QueryRunner runner=new QueryRunner();
    @Override
    public BgUser login(String username, String pass) {
        Connection connection = DruidUtils.getConnection();
        BgUser user=null;
        String sql ="select * from bguser where user=? and pass=?";

        try {
            user = runner.query(connection, sql, new BeanHandler<>(BgUser.class),username,pass);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }
        return user;
    }
}
